import { request, requestList, RequestError } from '../util/http'
import RequestResult from '../api/RequestResult'
import RequestListResult from '../api/RequestListResult'
import BaseModel from "./BaseModel";

import Account from './model/Account'
import Push from './model/Push'
import TurnoverMonth from './model/TurnoverMonth'
import Order from './model/Order'
import Buyer from './model/Buyer'
import Product from './model/Product'
import Supplier from './model/Supplier'
import ProductCategory from './model/ProductCategory'
import Repository from './model/Repository'
import SystemConfig from './model/SystemConfig'

export const PAGE_SIZE = 20
export const BASE_URL = "https://vem.kollway.com"
export const DEMO_URL = "http://localhost:3031"


/**
 * 登录
 */
export function accountApiLogin(
    parameters: {
        account: string,
        password: string,
    },
    success: (result: RequestResult<Account>) => void,
    failure: (error: RequestError) => void
) {
    request<Account>(
        'POST',
        '/AccountApi/login',
        {...parameters},
        success,
        failure
    )
}
/**
 * 批发商登录
 */
export function accountApiLoginWholesalerH5(
    parameters: {
        account: string,
        password: string,
    },
    success: (result: RequestResult<Account>) => void,
    failure: (error: RequestError) => void
) {
    request<Account>(
        'POST',
        '/AccountApi/loginWholesalerH5',
        {...parameters},
        success,
        failure
    )
}
/**
 * 刷新账号信息
 */
export function accountApiRefresh(
    parameters: {
    },
    success: (result: RequestResult<Account>) => void,
    failure: (error: RequestError) => void
) {
    request<Account>(
        'GET',
        '/AccountApi/refresh',
        {...parameters},
        success,
        failure
    )
}
/**
 * 消息列表
 */
export function accountApiListMessage(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Push>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Push>(
        'GET',
        '/AccountApi/listMessage',
        {...parameters},
        success,
        failure
    )
}
/**
 * 年营业额数据
 */
export function accountApiListTurnover(
    parameters: {
        page: number,
        year: string,
    },
    success: (result: RequestListResult<TurnoverMonth>) => void,
    failure: (error: RequestError) => void
) {
    requestList<TurnoverMonth>(
        'GET',
        '/AccountApi/listTurnover',
        {...parameters},
        success,
        failure
    )
}
/**
 * 设置缺货提醒临界数
 */
export function accountApiSetProduct(
    parameters: {
        product_id: number,
        less_remind_value: number,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'POST',
        '/AccountApi/setProduct',
        {...parameters},
        success,
        failure
    )
}
/**
 * 下单
 */
export function orderApiAddOrder(
    parameters: {
        buyer_phone: string,
        buyer_name: string,
        remark: string,
        products: string,
        wholesaler_token: string,
    },
    success: (result: RequestResult<Order>) => void,
    failure: (error: RequestError) => void
) {
    request<Order>(
        'POST',
        '/OrderApi/addOrder',
        {...parameters},
        success,
        failure
    )
}
/**
 * 自助下单前检查库存(H5页面专用)
 */
export function orderApiCheckOrderStockH5(
    parameters: {
        wholesaler_token: string,
        products: string,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'GET',
        '/OrderApi/checkOrderStockH5',
        {...parameters},
        success,
        failure
    )
}
/**
 * 根据手机号获取顾客信息
 */
export function orderApiGetBuyer(
    parameters: {
        phone: string,
    },
    success: (result: RequestResult<Buyer>) => void,
    failure: (error: RequestError) => void
) {
    request<Buyer>(
        'GET',
        '/OrderApi/getBuyer',
        {...parameters},
        success,
        failure
    )
}
/**
 * 订单详情
 */
export function orderApiDetail(
    parameters: {
        order_id: number,
    },
    success: (result: RequestResult<Order>) => void,
    failure: (error: RequestError) => void
) {
    request<Order>(
        'GET',
        '/OrderApi/detail',
        {...parameters},
        success,
        failure
    )
}
/**
 * 登录入库接口
 */
export function stockApiLoginStock(
    parameters: {
        password: string,
    },
    success: (result: RequestResult<Account>) => void,
    failure: (error: RequestError) => void
) {
    request<Account>(
        'POST',
        '/StockApi/loginStock',
        {...parameters},
        success,
        failure
    )
}
/**
 * 新增库存产品
 */
export function stockApiAdd(
    parameters: {
        name: string,
        quantity: number,
        cost_price: number,
        price: number,
        unit: string,
        assist_unit: string,
        standard: string,
        model: string,
        color: string,
        place: string,
        barcode: string,
        supplier_id: number,
        repository_id: number,
        category_id: number,
        remark: string,
        is_wholesaler_product: number,
        cover_image_url: string,
        cover_image: string,
    },
    success: (result: RequestResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    request<Product>(
        'POST',
        '/StockApi/add',
        {...parameters},
        success,
        failure
    )
}
/**
 * 库存详情
 */
export function stockApiDetail(
    parameters: {
        barcode: string,
    },
    success: (result: RequestResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    request<Product>(
        'GET',
        '/StockApi/detail',
        {...parameters},
        success,
        failure
    )
}
/**
 * 扫描条形码获取产品详情
 */
export function stockApiBarcodeScan(
    parameters: {
        barcode: string,
    },
    success: (result: RequestResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    request<Product>(
        'GET',
        '/StockApi/barcodeScan',
        {...parameters},
        success,
        failure
    )
}
/**
 * 编辑库存产品
 */
export function stockApiEdit(
    parameters: {
        product_id: number,
        supplier_id: number,
        repository_id: number,
        quantity: number,
        cost_price: number,
        price: number,
    },
    success: (result: RequestResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    request<Product>(
        'POST',
        '/StockApi/edit',
        {...parameters},
        success,
        failure
    )
}
/**
 * 修改产品信息(目前只能修改图片)
 */
export function stockApiUpdate(
    parameters: {
        product_id: number,
        cover_image: string,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'POST',
        '/StockApi/update',
        {...parameters},
        success,
        failure
    )
}
/**
 * 库存产品列表&#x2F;搜索
 */
export function stockApiList(
    parameters: {
        page: number,
        category_id: number,
        by_keyword: string,
        by_letter: string,
    },
    success: (result: RequestListResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Product>(
        'GET',
        '/StockApi/list',
        {...parameters},
        success,
        failure
    )
}
/**
 * 供应商列表
 */
export function stockApiListSupplier(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Supplier>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Supplier>(
        'GET',
        '/StockApi/listSupplier',
        {...parameters},
        success,
        failure
    )
}
/**
 * 临近缺货产品列表
 */
export function stockApiListLessProduct(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Product>(
        'GET',
        '/StockApi/listLessProduct',
        {...parameters},
        success,
        failure
    )
}
/**
 * 缺货产品列表
 */
export function stockApiListSoldOutProduct(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Product>(
        'GET',
        '/StockApi/listSoldOutProduct',
        {...parameters},
        success,
        failure
    )
}
/**
 * 产品详情(H5页面专用)
 */
export function stockApiDetailH5(
    parameters: {
        wholesaler_token: string,
        product_code: string,
    },
    success: (result: RequestResult<Product>) => void,
    failure: (error: RequestError) => void
) {
    request<Product>(
        'GET',
        '/StockApi/detailH5',
        {...parameters},
        success,
        failure
    )
}
/**
 * 产品分类列表
 */
export function stockApiCategories(
    parameters: {
        page: number,
        pid: number,
    },
    success: (result: RequestListResult<ProductCategory>) => void,
    failure: (error: RequestError) => void
) {
    requestList<ProductCategory>(
        'GET',
        '/StockApi/categories',
        {...parameters},
        success,
        failure
    )
}
/**
 * 仓库列表
 */
export function stockApiListRepositories(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Repository>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Repository>(
        'GET',
        '/StockApi/listRepositories',
        {...parameters},
        success,
        failure
    )
}
/**
 * 待接的待拣订单列表
 */
export function orderApiListPickWait(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Order>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Order>(
        'GET',
        '/OrderApi/listPickWait',
        {...parameters},
        success,
        failure
    )
}
/**
 * 已接的待拣订单列表
 */
export function orderApiListPickFinish(
    parameters: {
        page: number,
    },
    success: (result: RequestListResult<Order>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Order>(
        'GET',
        '/OrderApi/listPickFinish',
        {...parameters},
        success,
        failure
    )
}
/**
 * 接拣单
 */
export function orderApiPickOrder(
    parameters: {
        order_id: number,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'POST',
        '/OrderApi/pickOrder',
        {...parameters},
        success,
        failure
    )
}
/**
 * 确认拣齐
 */
export function orderApiFinishPickOrder(
    parameters: {
        order_id: number,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'POST',
        '/OrderApi/finishPickOrder',
        {...parameters},
        success,
        failure
    )
}
/**
 * 某天的订单列表
 */
export function orderApiListOrderByDate(
    parameters: {
        page: number,
        date: string,
    },
    success: (result: RequestListResult<Order>) => void,
    failure: (error: RequestError) => void
) {
    requestList<Order>(
        'GET',
        '/OrderApi/listOrderByDate',
        {...parameters},
        success,
        failure
    )
}
/**
 * 确认收款
 */
export function orderApiConfirmPay(
    parameters: {
        order_id: number,
        pay_type: number,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'POST',
        '/OrderApi/confirmPay',
        {...parameters},
        success,
        failure
    )
}
/**
 * 发送验证码短信
 */
export function smsApiSendVerifySms(
    parameters: {
        phone: string,
    },
    success: (result: RequestResult<BaseModel>) => void,
    failure: (error: RequestError) => void
) {
    request<BaseModel>(
        'POST',
        '/SmsApi/sendVerifySms',
        {...parameters},
        success,
        failure
    )
}
/**
 * 获取系统配置
 */
export function systemApiGetConfig(
    parameters: {
    },
    success: (result: RequestResult<SystemConfig>) => void,
    failure: (error: RequestError) => void
) {
    request<SystemConfig>(
        'GET',
        '/SystemApi/getConfig',
        {...parameters},
        success,
        failure
    )
}


